package routers

import (
	"GoAdmin/controller"
	"GoAdmin/middleware"

	"github.com/gin-contrib/cors"

	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {

	//获取router路由对象
	r := gin.New()
	gin.SetMode(gin.DebugMode)
	config := cors.DefaultConfig()
	config.AllowAllOrigins = true
	config.AllowHeaders = append(config.AllowHeaders, "Authorization")
	r.Use(cors.New(config))

	r.GET("/test", controller.Test)   // 用户登录
	r.GET("/test/long", controller.T) // 用户登录
	authRouter := r.Group("/auth")
	{
		authRouter.GET("/add", controller.GetAuth)
		authRouter.POST("/login", controller.Login)
		authRouter.POST("/role", controller.GetUserRole)
	}
	school := r.Group("/school").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		school.GET("/getMenuList", controller.GetMenuNew)      //新版查询菜单列表
		school.POST("/list", controller.SchoolList)            //所有驾校名称列表
		school.POST("/detail", controller.SchoolDetail)        //驾校详细信息
		school.POST("/city", controller.CityList)              //所有城市代码
		school.POST("/add/number", controller.AddSchoolNumber) //添加学员名额
		school.POST("/order/list", controller.PayOrderList)    //添加名额账单列表
		school.POST("/quota", controller.AllSchoolList)        //查询驾校
	}
	// record := r.Group("/record")
	record := r.Group("/record").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		record.POST("/list", controller.RecordList) //学时列表
		//record.POST("/fail/list", controller.RecordFailListTest)        //未备案学时列表
		record.POST("/fail/survey", controller.RecordFailSurvey)                    //学时详情
		record.POST("/stage/list", controller.StageList)                            //阶段列表
		record.POST("/stage/report/list", controller.StageReportList)               //审核列表
		record.POST("/stage/training/record/new", controller.StageTrainTimeNewTest) // 阶段学时上报生成pdf 山东使用测试
		record.POST("/stage/training/record", controller.StageTraining)             //阶段学时上报生成pdf
		record.POST("/stage/sign", controller.StageSing)                            //上报到省平台
		record.POST("/stage/review", controller.StageQuery)                         //查询审核结果
		record.POST("/stage/detail", controller.StageDetail)                        //查询审核结果详细信息
		record.POST("/removeToTask", controller.ReMoveToTask)                       //移回到阶段学时
		record.POST("/reset_minute", controller.ResetMinute)                        //重置分钟数，针对学时为0的做处理
		record.POST("/clear_minute", controller.ClearMinute)                        //分钟数清零
		record.POST("/pdf", controller.GetPdf)                                      //获取PDF
		record.POST("/learn_record", controller.ClassRecord)                        // 备案学时
		record.GET("/recordFile", controller.RecordFile)                            // 补传照片
	}
	// coach := r.Group("/coach")
	coach := r.Group("/coach").Use(middleware.VerifyToken())
	//coach := r.Group("/coach").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		coach.POST("/information", controller.CoachInformation) //教练列表
		coach.POST("/detail", controller.CoachDetail)           //教练详细信息
		coach.POST("/record/list", controller.CoachRecordList)  //教练带教记录
		coach.POST("/logout", controller.CoachLogout)           //教练登出
		//coach.POST("/delete", controller.CoachDelete)           //教练删除
		coach.POST("/add", controller.CoachAdd)       //教练添加
		coach.POST("/record", controller.RecordCoach) //教练备案
		coach.POST("/delete", controller.CoachDelete) //教练删除

	}
	security := r.Group("/security").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		security.POST("/information", controller.SecurityList) //安全员列表
	}
	examiner := r.Group("/examiner").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		examiner.POST("/information", controller.ExaminerList) //安全员列表
	}
	// car := r.Group("/car")
	car := r.Group("/car").Use(middleware.VerifyToken())
	//car := r.Group("/car").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		car.POST("/information", controller.CarInformation) //车辆列表
		car.POST("/detail", controller.CarDetail)           //车辆详情信息
		car.POST("/record/list", controller.CarRecordList)  //车辆带教记录
		car.POST("/add", controller.CarAdd)                 //添加车辆
	}
	terminal := r.Group("/terminal").Use(middleware.VerifyToken())
	//terminal := r.Group("/terminal").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		terminal.POST("/add", controller.TerminalAdd)                      //添加终端
		terminal.POST("/delete", controller.TerminalDelete)                //删除终端
		terminal.POST("/information", controller.TerminalInformation)      //终端列表
		terminal.POST("/bingding", controller.BingDing)                    //绑定终端
		terminal.POST("/rembinding", controller.RemBingDing)               //解绑终端
		terminal.POST("/deleteterminal", controller.DeleteTerminal)        //删除终端
		terminal.POST("/cancel", controller.CancelTerminal)                //注销终端
		terminal.POST("/unrecord/list", controller.TerminalUnRecordList)   //终端未备案学时
		terminal.POST("/car/record/list", controller.TerminalUnRecordList) //车辆终端学时
		terminal.POST("/todo/record", controller.TodoRecord)               //处理未备案学时
		terminal.POST("/version/list", controller.GetVersionList)          //版本升级列表
		terminal.POST("/version/change", controller.ChangeVersion)         //开关版本
		terminal.POST("/version/upload", controller.UploadApk)             //上传版本
	}
	field := r.Group("/field").Use(middleware.VerifyToken())
	//field := r.Group("/field").Use(middleware.VerifyToken()).Use(middleware.Authorize())
	{
		field.POST("/information", controller.FieldList)             //场地信息
		field.POST("/get/closure/point", controller.GetClosurePoint) //获取驾校围栏坐标点信息
		//field.POST("/get/point", controller.GetPoint)    //电子围栏
	}
	// 班级添加
	class := r.Group("/class")
	{
		class.POST("/information", controller.CharList) //收费标准 班级列表
	}

	// student := r.Group("/student")
	student := r.Group("/student").Use(middleware.VerifyToken())
	{
		student.POST("/information", controller.StudentInformation)            //查询学员
		student.POST("/export", controller.StudentExport)                      //导出学员
		student.POST("/detail", controller.StudentDetail)                      //学员信息详情
		student.POST("/toC1", controller.ToC1)                                 //学员转C1
		student.POST("/transfer/status", controller.StudentTransfer)           //修改转入状态
		student.POST("/unregister/list", controller.UnRegisterList)            //解除备案列表
		student.POST("/unregister/restore", controller.UnRegisterRestore)      //删除学员恢复
		student.POST("/need/graduation", controller.NeedGraduationStudentList) //待结业学员

		//student.POST("/record", controller.Record)                       //学员学时信息详情
		student.POST("/unregisterStudent", controller.UnregisterStudent) //学员删除
		student.POST("/order/list", controller.StudentOrder)             //买名额账单
		student.POST("/pay/add", controller.StudentOrderAdd)             //买名额账单新增
		student.POST("/pay/status", controller.StudentOrderPay)          //买名额账单改状态
		student.POST("/pay/delete", controller.StudentOrderDelete)       //买名额账单删除
		student.POST("/removeJieYe", controller.RemoveJieYe)             //删除已结业
		student.POST("/push/ky", controller.PushToKy)                    //推送到快鸭
		student.POST("/unregister/ky", controller.DelFromKy)             //删除学员推送快鸭
	}
	role := r.Group("/role").Use(middleware.VerifyToken())
	{
		// 角色管理
		role.POST("/get/menu", controller.GetUserMenu)      //获取登录用户菜单
		role.POST("/add", controller.AddRole)               //添加角色
		role.GET("/list", controller.GetRoleList)           //获取权限列表
		role.POST("/set/user_role", controller.SetUserRole) //角色分配权限
		role.POST("/edit/name", controller.EditRole)        //编辑角色信息
		role.GET("/get/user_role", controller.GetUserRole)  //获取角色的权限
		role.POST("/delete", controller.DelUserRole)        //删除角色
		//role.POST("/set/user_role", controller.SetUserRole)  //保存角色的权限

		//用户管理
		role.POST("/user/add", controller.AddRoleUser)     //添加角色
		role.POST("/user/edit", controller.EditRoleUser)   //编辑用户
		role.GET("/user/list", controller.GetRoleUserList) //获取用户列表
		role.POST("/get/list", controller.GetAllRoleList)  //获取权限列表
	}
	configs := r.Group("/config").Use(middleware.VerifyToken())
	{
		configs.GET("/info", controller.SchoolConfig) //驾校配置
		configs.POST("/set", controller.SetConfig)    //保存驾校配置
		configs.GET("/user/log", controller.UserLog)  //用户操作日志
	}
	theory := r.Group("/theory").Use(middleware.VerifyToken())
	{
		theory.POST("/student", controller.ApiSearchStudent)
		theory.POST("/upload/file", controller.UploadSimulatorRecordFile)
		theory.POST("/upload/record", controller.SimulatorStudentLogin)
	}
	return r
}
